<template>
  <div class="home-page">
    <Top />
    <el-row :gutter="20" style="margin-top: 25px;margin-bottom: 25px">
      <el-col :span="18">
        <Top2 />
      </el-col>
      <el-col :span="6">
        <div class="card card2" style="height: 504px">
          <div class="title">
            统计会议类别数据
          </div>
            <v-chart class="f-s" style="width: 100%;height: 220px" :option="pieOption" autoresize/>
            <div class="legend-list-pie f-w f-r ">
                <div v-for="item in pieLegendList" :key="item.name" class="legend-item-pie">
                    <div class="f-r">
                        <div class="legend-item-pie-icon" :style="{ backgroundColor: item.color }" />
                        <div>
                            <div class="legend-item-pie-name">
                                {{ item.name }}
                            </div>
                            <div class="f-r a-c">
                                <div class="legend-item-pie-percent">
                                    {{ item.proportion }}%
                                </div>
                                <div class="legend-item-pie-value" :style="{ color: item.color }">
                                    {{ item.value }}
                                    <span class="unit">元</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
      </el-col>
    </el-row>
    <el-row style="margin-top: 25px;margin-bottom: 25px">
      <el-col>
        <div class="card card2" style="width: 100%">
          <div class="title">
            会议分析
          </div>
          <v-chart style="width: 100%;height: 220px" :option="barOption" autoresize/>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col>
        <div class="card card2">
          <div class="f-r a-c j-b">
            <div class="title">
              会议安排
            </div>
            <el-button type="text" @click="toMeeting">查看更多 > </el-button>
          </div>
          <el-table
            height="260px"
            :data="tableData"
          >
            <el-table-column
              v-for="item in columns"
              :key="item.prop"
              :prop="item.prop"
              :label="item.label"
              align="center"
            />
          </el-table>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { http } from '@/api'
import Top from './top'
import Top2 from './top2'
import {EnterpriseType, getName, Investor, ProjectStatus, ProjectType, MeetingType} from "@/dict";
export default {
  name: 'Home',
  components: {
    Top,
    Top2
  },
  data() {
    return {
      meet:['','规划设计方案','工可评审','初步设计','工程变更'],
      pieOption: {
        'title': {
          'text': 0,
          'subtext': '总数(元)',
          'x': 'center',
          'y': '35%',
          'textStyle': {
            'color': '#000',
            'fontSize': 40,
            'fontWeight': 'bold',
            'align': 'center',
            'width': '200px'
          },
          'subtextStyle': {
            'color': '#999999',
            'fontSize': 18,
            'fontWeight': 'normal',
            'align': 'center'
          }
        },
        'series': [{
          'type': 'pie',
          'center': ['50%', '50%'],
          'radius': ['65%', '90%'],
          'color': ['#2251F8', '#F87C22', '#AB31E4', '#50D37D'],
          labelLine: {
            show: false
          },
          label: {
            show: false
          },
          'data': [
            ]
        }]
      },
        pieLegendList: [
            { name: '大数据局', value: '12.5', percent: '25', color: '#2251F8' },
            { name: '发改局', value: '6.5', percent: '22', color: '#F87C22' },
            { name: '经信局', value: '9.5', percent: '19', color: '#AB31E4' },
            { name: '资规局', value: '17', percent: '34', color: '#50D37D' }
        ],
      barOption: {},
      tableData: [],
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'meetingTypeName', label: '会议类别' },
        { prop: 'investorName', label: '组织单位' },
        { prop: 'meetingStartTime', label: '会议开始时间' },
        { prop: 'meetingName', label: '会议室' }
      ]
    }
  },
  async created() {
      const userRes = await http.home.meetingUser()
      this.getmeet()
      
      this.barOption = {
          legend: {
              show: true,
              orient: 'horizontal',
              icon: 'circle',
              right: 10,
              top: 0,
              data: ['会议数量', '参会专家人数','节约资金'],
              itemGap: 20,
              textStyle: {
                  color: '#282D32',
                  fontSize: 14,
                  fontWeight: 'bold'
              }
          },
          grid: {
              top: 40,
              left: 32,
              right: 32,
              bottom: 0,
              containLabel: true
          },
          tooltip: {
              show: true,
              trigger: 'axis'
          },
          xAxis: {
              type: 'category',
              axisLine: {
                  lineStyle: {
                      color: 'rgba(238, 238, 238, 1)'
                  }
              },
              axisLabel: {
                  color: 'rgba(43,48,52,0.4)',
                  fontSize: 12
              },
              axisTick: {
                  show: false
              },
              data: userRes.data.map(el => el.time)
          },
          yAxis: [{
              type: 'value',
              axisLabel: {
                  color: 'rgba(43,48,52,0.4)',
                  fontSize: 12
              },
              splitLine: {
                  lineStyle: {
                      color: 'rgba(238, 238, 238, 1)'
                  }
              }
          }
           , {
            axisLabel: {
                  color: 'rgba(43,48,52,0.4)',
                  fontSize: 12
              },
              splitLine: {
                  lineStyle: {
                      color: 'rgba(238, 238, 238, 1)'
                  }
              },
              type: 'value',
              name: '',
              axisLabel: {
                formatter: '{value} 元'
              }
            }],
          series: [
              {
                  name: '会议数量',
                  data:  userRes.data.map(el => el.meetingSum),
                  type: 'bar',
                  itemStyle: {
                      color: '#2251F8'

                  },
                  barWidth: 16
              },
              {
                  name: '参会专家人数',
                  data:  userRes.data.map(el => el.expertsSum),
                  type: 'bar',
                  itemStyle: {
                      color: '#F87C22'

                  },
                  barWidth: 16,
                  borderRadius: [8,8,0,0]
              },
              {
                  name: '节约资金',
                  data:  userRes.data.map(el => el.savingCapital),
                  yAxisIndex: 1,
                  type: 'bar',
                  itemStyle: {
                      color: '#AB31E4'

                  },
                  barWidth: 16
              },
          ]
      }
      http.meeting_apply.page().then(res => {
          res.data.records.forEach(el => {
              el.projectTypeName = getName(el.category, ProjectType)
              el.investorName = getName(el.investor, Investor)
              el.statusName = getName(el.status, ProjectStatus)
              el.enterpriseTypeName = getName(el.enterpriseType, EnterpriseType)
              el.meetingTypeName = getName( el.meetingType, MeetingType)
          })
          this.tableData = res.data.records
      })
  },
  methods: {
    toMeeting() {
      this.$router.push('/meeting/apply')
    },
    getmeet(){

      http.home.SavingList().then(res => {
        this.pieLegendList = res.data.type
      console.log(this.pieLegendList);
      let color = ['#2251F8', '#F87C22', '#AB31E4', '#50D37D']
      let list = []
      this.pieLegendList.forEach((element,i) => {
        console.log(i);
        element.name = this.meet[element.meetingType]
        element.value = element.statistics
        element.color = color[i]
        list.push({name:element.name,value:element.value})
      });
      this.pieOption.title.text = res.data.sum
      this.pieOption.series[0].data = list
              })


      
    }
  }
}
</script>

<style scoped lang="scss">
.home-page {
    min-width: 1400px;
    .legend-list-pie {
        margin-top: 30px;
        .legend-item-pie {
            width: 50%;
            margin-bottom: 10px;
        }
        .legend-item-pie-icon {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            margin-right: 12px;
        }
        .legend-item-pie-name {
            font-size: 14px;
            font-family: Source Han Sans CN;
            font-weight: 400;
            color: #171B1E;
        }
        .legend-item-pie-percent {
            font-size: 18px;
            font-family: DIN;
            font-weight: 500;
            color: #171B1E;
            margin-right: 14px;
        }
        .legend-item-pie-value {
            font-size: 16px;
            font-family: DIN;
            font-weight: 500;
            color: #2251F8;
            .unit {
                font-size: 12px;
                line-height: 14px;
            }
        }
    }

    .title {
        font-size: 20px;
        color: #333333;
        font-weight: bold;
        margin-bottom: 24px;
    }
    .card {
        background: #FFFFFF;
        box-shadow: 6px 6px 54px 1px rgba(0,0,0,0.05);
        border-radius: 14px 14px 14px 14px;
    }
    .card1 {
        width: 100%;
        height: 161px;
        padding: 16px;
        color: #202224;
        font-size: 16px;
        .name {
            font-weight: 400;
            line-height: 16px;
            margin-bottom: 11px;
        }
        .value {
            font-size: 36px;
            line-height: 44px;
        }
        .value-box {
            margin-bottom: 32px;

        }
        .unit {
            font-size: 16px;
            line-height: 16px;
        }
        .text {
            color: #12163C;
        }
        .color-l {
            color: #00B69B;
        }
        .icon {
            width: 60px;
            height: 60px;
        }
    }
    .card2 {
       padding: 20px;
    }
}
</style>
